<template>
  <div id="topSearch">
    <div class="search-box">
      <el-form ref="ruleForm" :inline="true" :model="formInline">
        <el-form-item label="大鹏号" prop="dpAccount">
          <el-input
            v-model="formInline.dpAccount"
            placeholder="请输入大鹏号"
            maxlength="50"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="活动名称" prop="activityId">
          <el-select
            clearable
            v-model="formInline.activityId"
            placeholder="请输入活动名称"
          >
            <el-option
              v-for="item in activityAll"
              :key="item.activityId"
              :label="item.activityName"
              :value="item.activityId"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="状态" prop="status">
          <el-select v-model="formInline.status" clearable placeholder="全部">
            <el-option
              v-for="item in statusOption"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="时间" prop="time">
          <el-date-picker
            style="width:400px"
            v-model="formInline.time"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd HH:mm:ss"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item class="s-btn">
          <el-button type="success" icon="el-icon-search" @click="toSearch">
            查询
          </el-button>
          <el-button type="success" plain @click="reset">
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { getAllActivity } from '@/api/activityCenter/activityManage/inviteHaveGift'
export default {
  data() {
    return {
      formInline: {
        dpAccount: '',
        activityId: '',
        status: '',
        startTime: '',
        endTime: '',
        time: []
      },
      activityAll: [],
      statusOption: [
        { value: 'NO', label: '未发放' },
        { value: 'YES', label: '已发放' }
      ]
    }
  },
  watch: {
    'formInline.time': {
      handler(val) {
        this.formInline.startTime = val && val.length ? val[0] : ''
        this.formInline.endTime = val && val.length ? val[1] : ''
      },
      deep: true
    }
  },
  mounted() {
    getAllActivity({}, (res) => {
      this.activityAll = res
    })
  },
  methods: {
    toSearch() {
      const obj = Object.assign({}, this.formInline)
      delete obj.time
      this.$emit('toSearch', obj)
    },
    /* 重置 */
    reset() {
      this.$refs['ruleForm'].resetFields()
    }
  }
}
</script>
<style lang="less" scoped></style>
